# -*-coding: utf-8 -*-
# by zw on 2017/12/25


import logging

from sanic import response

from utils.mongo import get_col_by_name
from utils.mongo_id import str_to_objectId

_logger = logging.getLogger(__name__)


def get_history_col_name(col_name):
    return "history" + col_name


async def history(request):
    try:
        id = request.raw_args.get("id", "")
        col_name = request.raw_args.get("col_name", "")

        _logger.info("id col_name %s", id, col_name, request.host)
        res = get_col_by_name(col_name).find_one({"_id": str_to_objectId(id)}, {"_id": 0})
        return response.json({"code": 0, "message": "", "data": res})
    except Exception as e:
        _logger.exception(e)
        return response.json({"code": 4003, "message": "error message %s" % e, "data": {}})


async def add_history(col_name, before, after, user):
    pass
